﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace MINERP.DAL.Statistics
{
    public class SalemanAchievementDAL
    {
        public DataSet GetSalemanAchievement(DateTime startTime, DateTime endTime)
        {
            DataSet dsResult = new DataSet();
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("GetAllSaleManachievement");
            db.AddInParameter(dbCommand, "startTime", DbType.DateTime, startTime);
            db.AddInParameter(dbCommand, "endTime", DbType.DateTime, endTime);

            try
            {
                dsResult = db.ExecuteDataSet(dbCommand);
            }
            catch (Exception)
            {
                return null;
            }

            return dsResult;
        }


        /// <summary>
        /// 获得时间段内销售的产品数量，面积及金额
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public DataSet GetSalesProductStatistics(DateTime startTime, DateTime endTime,int status)
        {
            DataSet dsResult = new DataSet();
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("GetSalesProductsStatistics");
            db.AddInParameter(dbCommand, "startTime", DbType.DateTime, startTime);
            db.AddInParameter(dbCommand, "endTime", DbType.DateTime, endTime);
            db.AddInParameter(dbCommand, "status",DbType.Int16,status);

            try
            {
                dsResult = db.ExecuteDataSet(dbCommand);
            }
            catch (Exception)
            {
                return null;
            }

            return dsResult;
        }
        /// <summary>
        /// 获得时间段内商户销售的产品数量，面积及金额
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public DataSet GetShopSalesProductStatistics(DateTime startTime, DateTime endTime, int shopid)
        {
            DataSet dsResult = new DataSet();
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("GetShopSalesProductsStatistics");
            db.AddInParameter(dbCommand, "startTime", DbType.DateTime, startTime);
            db.AddInParameter(dbCommand, "endTime", DbType.DateTime, endTime);
            db.AddInParameter(dbCommand, "shopID", DbType.Int32, shopid);

            try
            {
                dsResult = db.ExecuteDataSet(dbCommand);
            }
            catch (Exception)
            {
                return null;
            }

            return dsResult;
        }
    }
}
